using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using BigNumbers;

namespace TestBigNumbers
{
    /// <summary>
    /// Summary description for FormBigRat.
    /// </summary>
    public partial class TestBigRat : System.Windows.Forms.Form
    {
        public TestBigRat()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            try
            {
                BigRat r1 = c1();
                BigRat r2 = c2();
                txtRes.Text = (r1 + r2).ToString();
            }
            catch (Exception ex)
            { MessageBox.Show(ex.ToString()); }

        }

        private void FormBigRat_Load(object sender, System.EventArgs e)
        {
            btnSimplify.Text = "Simplify : " + BigRat.SimplifyOrder.ToString();
        }

        private void btnSub_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 - r2).ToString();
        }


        private void btnLT_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 < r2).ToString();
        }

        private void btnLTE_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 <= r2).ToString();
        }

        private void btnGTE_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 >= r2).ToString();
        }

        private void btnGT_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 > r2).ToString();
        }

        private void btnEQ_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 == r2).ToString();
        }

        private void btnDiff_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 != r2).ToString();
        }

        private void btnAbs_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = Calculus.Abs(i1).ToString();
        }

        private void btnToString_Click(object sender, System.EventArgs e)
        {
            txtRes.Text = c1().ToString();
            txtRes2.Text = c2().ToString();
        }

        private void btnInc_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            txtRes.Text = (++r1).ToString();
        }

        private void btnDec_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            txtRes.Text = (--r1).ToString();
        }

        private void btnMult_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 * r2).ToString();
        }

        private void btnFact_Click(object sender, System.EventArgs e)
        {
            long t1 = DateTime.Now.Ticks;
            BigInt i1 = new BigInt(txtInt1.Text);
            int i2 = Convert.ToInt32(txtInt2.Text);
            BigInt bi = Calculus.Fact(i1);
            long t2 = DateTime.Now.Ticks;
            txtRes.Text = bi.ToString();

            txtRes2.Text = ((t2 - t1) / 10000).ToString();
        }

        private void btnDiv_Click(object sender, System.EventArgs e)
        {
            BigRat r1 = c1();
            BigRat r2 = c2();
            txtRes.Text = (r1 / r2).ToString();
        }

        private void btnSimplify_Click(object sender, System.EventArgs e)
        {
            BigRat.SimplifyOrder = !BigRat.SimplifyOrder;
            btnSimplify.Text = "Simplify : " + BigRat.SimplifyOrder.ToString();
        }


        private void btnEven_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = Calculus.Even(i1).ToString();
        }

        private void btnPow_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            int i2 = Convert.ToInt32(txtInt2.Text);
            txtRes.Text = Calculus.Pow(i1, i2).ToString();
        }

        private void btnPow10_Click(object sender, System.EventArgs e)
        {
            int i1 = Convert.ToInt32(txtInt1.Text);
            txtRes.Text = Calculus.Pow10(i1).ToString();
        }

        private void btnSqrt_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = Calculus.Sqrt(i1);
            txtRes.Text = i2.ToString();
            txtRes2.Text = (i2 * i2).ToString();

        }

        private void btnCast_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = ((long)i1).ToString();
        }

        private void btnDivisors_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt[] tab = Calculus.Divisors(i1);
            StringBuilder s = new StringBuilder();
            foreach (BigInt i in tab)
            {
                s.Append(i.ToString());
                s.Append(",");
            }
            txtRes.Text = s.ToString();

        }

        private void btnFactors_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt[] tab = Calculus.PrimeFactors(i1);
            StringBuilder s = new StringBuilder();
            foreach (BigInt i in tab)
            {
                s.Append(i.ToString());
                s.Append(",");
            }
            txtRes.Text = s.ToString();

        }

        private void btnPPCM_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = Calculus.PPCM(i1, i2).ToString();
        }

        private void btnPGCD_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = Calculus.PGCD(i1, i2).ToString();
        }

        private void btnBigInt_Click(object sender, System.EventArgs e)
        {
            TestBigInt f = new TestBigInt();
            f.Show();
        }

        private BigInt test(BigInt x)
        {
            return x * x * x;
        }

        private BigRat c1()
        {
            return new BigRat(new BigInt(txtInt1.Text), new BigInt(txtRat1.Text));
        }

        private BigRat c2()
        {
            return new BigRat(new BigInt(txtInt2.Text), new BigInt(txtRat2.Text));
        }


    }

}

